<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="__static__/admin/css/style.css" rel="stylesheet" type="text/css" />
<link href="__static__/admin/css/select.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="__static__/admin/js/jquery.js"></script>
<script type="text/javascript" src="__static__/admin/js/jquery.idTabs.min.js"></script>
<script type="text/javascript" src="__static__/admin/js/select-ui.min.js"></script>
 
<script type="text/javascript">
$(document).ready(function(e) {
    $(".select1").uedSelect({
		width : 345			  
	});
	$(".select2").uedSelect({
		width : 167  
	});
	$(".select3").uedSelect({
		width : 100
	});
    $(".click").click(function(){
        $(".tip").fadeIn(200);
    });
    
    $(".tiptop a").click(function(){
        $(".tip").fadeOut(200);
    });

    $(".sure").click(function(){
        var nme = $('#hobbyName').val();
        if(!nme || nme=='') 
        return alert('名称不能为空');
        $.post('{:url("addFormulateInfo")}',{nme:nme,val:val},function(res){
            alert(res.msg)
            if(res.code == 1){
                window.location.reload();
                //$(".tip").fadeOut(100);
            }
        })
    });
    $(".cancel").click(function(){
        $('#hobbyName').val('');
        $(".tip").fadeOut(100);
    });
});
</script>
</head>

<body>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">首页</a></li>
    <li><a href="#">系统设置</a></li>
    </ul>
    </div>
    
    <div class="formbody">
    <div class="tools">
    
        <ul class="toolbar">
            <li class="click"><span><img src="__static__/admin/images/t01.png" /></span>添加</li>
            <li onclick="deleteAllFormulate()"><span><img src="__static__/admin/images/t03.png" /></span>删除</li>
        </ul>
    </div>
    <div id="usual1" class="usual"> 
    
  	<div id="" class="tabson">
    
    <table class="tablelist">
    	<thead>
    	<tr>
        <th><input name="checkboxs" type="checkbox" value=""/></th>
        <th>编号<i class="sort"><img src="__static__/admin/images/px.gif" /></i></th>
        <th>名称</th>
        <th>排序</th>
        <th>状态</th>
        <th>操作</th>
        </tr>
        </thead>
        <tbody>
          {foreach $formulate_list as $v}
          <tr>
            <td><input name="checkbox" type="checkbox" value="{$v.id}" /></td>
            <td>{$v.id}</td>
            <td><input type="text" id="FormulateName{$v.id}" value="{$v.Name}"/></td>
            <td><input type="number" id="FormulateSort{$v.id}" min="0" max="99" value="{$v.Sort}"/></td>
            <td>{$v.State|getAllToexamine}</td>
            <td>
                <a href="javascript:;editFormulateInfo({$v.id})" class="tablelink">修改</a> 
                <a href="javascript:;toexamineFormulate({$v.id},{$v.State})" class="tablelink">审核</a>    
                <a href="javascript:;deleteFormulate({$v.id})" class="tablelink"> 删除</a>
            </td>
          </tr> 
          {/foreach}
        </tbody>
    </table>
    
   
  
    
    </div>  
       
	</div>   
  </div>
   
    <div class="tip">
        <div class="tiptop"><span>提示信息</span><a></a></div>
        
        <div class="tipinfo">
            <span><img src="__static__/admin/images/ticon.png" /></span>
            <div class="tipright">
            <p>请输入名称1~20字 </p>
            <cite><input type="text" min="1" max="60" id="hobbyName" style="width: 100%;line-height:30px; background: gray;color: white;"/></cite>
            </div>
        </div>
        <div class="tipbtn">
            <input name="" type="button"  class="sure" value="确定" />&nbsp;
            <input name="" type="button"  class="cancel" value="取消" />
        </div>
    
    </div>

</body>
</html>
 
<script type="text/javascript"> 
    val = '{$val}';
    checkboxs = $('input[name="checkboxs"]');
    checkbox = $("input[name='checkbox']");
    function deleteFormulate(id){
        if(!confirm('确认删除此记录？')) return false;
        $.post('{:url("deleteFormulate")}',{id:id,val:val},function(res){
            console.log('返回数据',res)
            alert(res.msg)
            if(res.code) window.location.reload();
        })
    }
    function deleteAllFormulate(){
        if(!confirm('是否删除所有选中的记录？')) return false;
         var ids=0;  
        checkbox.each(function() {  
            if ($(this).is(':checked')) {  
                ids += ","+$(this).val();  
            }  
        });  
        console.log('选中',ids)
       $.post('{:url("deleteFormulate")}',{id:ids,val:val},function(res){
            console.log('返回数据',res)
            alert(res.msg)
            if(res.code) window.location.reload();
        })
    } 
    function toexamineFormulate(id,sta){
        $.post('{:url("toexamineFormulate")}',{id:id,sta:sta,val:val},function(res){
            console.log('返回数据',res)
            alert(res.msg)
            if(res.code) window.location.reload();
        })
    }
    function editFormulateInfo(id){
        var nme = $('#FormulateName'+id).val();
        var sto = $('#FormulateSort'+id).val();
        $.post('{:url("editFormulateInfo")}',{id:id,nme:nme,sto:sto,val:val},function(res){
            console.log('返回数据',res)
            alert(res.msg)
            window.location.reload();
        })
    }
    checkboxs.click(function(){
        if($(this).is(':checked')){
             checkbox.attr('checked',true);
        }else{
             checkbox.attr('checked',false);
        }
    })
    checkbox.click(function(){
        var ck = $("input[name='checkbox']").length;
        var cm = $("input[type='checkbox']:checked").length;
        $(this).each(function(){
              if(!$(this).is(':checked') || ck != cm){
                  checkboxs.attr('checked',false);
              }else{
                  checkboxs.attr('checked',true);
            }
          }
        )
    })

</script>
